package com.lxs.mall.common;

import com.google.common.collect.Sets;
import com.lxs.mall.exception.LxsMallException;
import com.lxs.mall.exception.LxsMallExceptionEnum;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @author 小松
 */
@Component
public class Constant {
    public static final String SALT = "asdaf@`a84sads5..1tuj2ffas76[lxs]";
    public static final String LXS_MALL_USER = "lxs_mall_user";
    public static final String EMAIL_FROM = "2946540828@qq.com";
    public static final String EMAIL_SUBJECT = "您的验证码";
    public static final Integer IMAGE_SIZE = 500;
    public static final Float IMAGE_OPACITY = 0.9f;
    public static final String WATER_MARK_JPG  = "watermark.jpg";

    public static String FILE_UPLOAD_DIR;

    /**
     * 静态变量的Value()需要放到set上才能生效，非静态的就不需要
     * 并且静态变量的set还需要去除掉前面的static关键字
     * @param fileUploadDir
     */
    @Value("${file.upload.dir}")
    public void setFileUploadDir(String fileUploadDir) {
        FILE_UPLOAD_DIR = fileUploadDir;
    }

    public interface ProductListOrderBy {
        Set<String> PRICE_ASC_DESC = Sets.newHashSet("price desc", "price asc");
    }



    public interface SellStatus {
        int NOT_SELL = 0;//下架中
        int SELL = 1;//上架中
    }

    public interface CartSelected {
        int NOT_CHECKED = 0;//未勾选
        int CHECKED = 1;//勾选
    }

    public enum OrderStatusEnum {

        CANCELED(0, "已取消"),
        NON_PAYMENT(10, "未付款"),
        ACCOUNT_PAID(20, "已付款"),
        DELIVERED(30, "已发货"),
        COMPLETEnterACTION(40, "交易完成");

        Integer code;
        String value;

        OrderStatusEnum(Integer code, String value) {
            this.code = code;
            this.value = value;
        }

        public static OrderStatusEnum codeOf(Integer code) {
            for (OrderStatusEnum orderStatusEnum : values()) {
                if (orderStatusEnum.getCode().equals(code)) {
                    return orderStatusEnum;
                }
            }
            throw new LxsMallException(LxsMallExceptionEnum.NO_ENUM);
        }

        public Integer getCode() {
            return code;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }
    public static final String JWT_KEY = "lxs_mall";
    public static final String JWT_TOKEN = "jwt_token";
    public static final String USER_NAME = "user_name";
    public static final String USER_ID = "user_id";
    public static final String USER_ROLE = "user_role";
    public static final String OPTIONS = "OPTIONS";
    /**
     * 单位是毫秒
     */
    public static final Long EXPIRE_TIME = 60 * 1000 * 60 * 24 * 100L;
}
